#!/bin/bash -x

bri="br0"
tap="tap"
ip="10.0.0.1/24"
broadcast="10.0.0.255"

drive0="./1.qcow2"
drive1="./2.qcow2"
fw="./fw_payload_oe_qemuvirt.elf"

vcpu=8
memory=8
memory_append=`expr $memory \* 1024`

qemu-system-riscv64 \
-nographic -machine virt \
-cpu rv64,sv39=on -smp ${vcpu} -m ${memory}G \
-audiodev pa,id=snd0 \
-kernel $fw \
-bios none \
-append 'root=/dev/vda1 rw console=ttyS0 swiotlb=1 loglevel=3 systemd.default_timeout_start_sec=600 selinux=0 highres=off mem="$memory_append"M earlycon' \
-drive file=${drive1},format=qcow2,id=hd0,if=none \
-object rng-random,filename=/dev/urandom,id=rng0 \
-device qemu-xhci -usb -device usb-kbd -device usb-tablet -device usb-audio,audiodev=snd0 -device virtio-rng-device,rng=rng0 \
-device virtio-blk-device,drive=hd0 \
-netdev tap,id=net${tap}1,ifname=${tap}1,script=no,downscript=no \
-device virtio-net-pci,netdev=net${tap}1,mac=52:54:00:11:45:03 \
-netdev user,id=usernet,hostfwd=tcp::12056-:22 \
-device virtio-net-pci,netdev=usernet,mac=52:54:00:11:45:04
